#include <cstring>
#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int N, M;
const int MAXN = 500010;

int a;
long long ans = 0;
long long sum[MAXN];

int main()
{
    cin >> N >> M;
    

    for (int i = 1; i <= N; i++)
    {
        cin >> a;
        sum[i] = sum[i - 1] + a; //前缀和
    }
    int len = M +1; //单调队列维护[i-len+1, i]最小值 要求i~i+len 需要知道sum[i]和sum[i-len] 所以len要+1
    deque<int> q;    //双端队列 维护最小值

    for (int i = 1; i <= N; i++)
    {
        while (!q.empty() && sum[q.back()] > sum[i])
        {
            q.pop_back(); //去尾
        }
        q.push_back(i); //入队

        while (!q.empty() && q.front() <= i-len)
        {
            q.pop_front(); //删头
        }
        //此时队首为i-M 到 i的最小值
        ans = max(ans, sum[i] - sum[q.front()]);

    } //维护区间
    cout << ans << endl;
    system("pause");
    return 0;
}
